//
//  ZZTabBarViewController.m
//  ZuZuBao
//
//  Created by Felix on 2024/4/8.
//

#import "ZZTabBarViewController.h"
#import "ZZHomeViewController.h"
#import "ZZRankViewController.h"
#import "ZZMyViewController.h"

@interface ZZTabBarViewController ()

@end

@implementation ZZTabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self createControllers];
}

- (void)createControllers {
    [self initController:[ZZHomeViewController new] title:@"首页" image:@"tab_home_1" selectedImage:@"tab_home_2"];
    [self initController:[ZZRankViewController new] title:@"热榜" image:@"tab_rank_1" selectedImage:@"tab_rank_2"];
    [self initController:[ZZMyViewController new] title:@"我的" image:@"tab_my_1" selectedImage:@"tab_my_2"];
}

- (void)initController:(UIViewController *)vc title:(NSString *)title image:(NSString *)imageName selectedImage:(NSString *)selectedImageName{
    
    vc.tabBarController.tabBar.backgroundColor = [UIColor whiteColor];
    vc.tabBarController.tabBar.translucent = NO;
    
    //1.取消系统自带的渲染模式
    vc.tabBarItem.image = [[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    vc.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    //2.修改tabbar 文字的颜色
    NSMutableDictionary* dic = [NSMutableDictionary dictionary];
    dic[NSForegroundColorAttributeName] = kRGBAColor(0x0E50F8, 1);
    [vc.tabBarItem setTitleTextAttributes:dic forState:UIControlStateSelected];
    
    dic[NSForegroundColorAttributeName] = kRGBAColor(0x333333, 1);
    [vc.tabBarItem setTitleTextAttributes:dic forState:UIControlStateNormal];
    
    if (@available(iOS 13.0, *)) {
        [[UITabBar appearance] setUnselectedItemTintColor: kRGBAColor(0x333333, 1)];

    }
    vc.title = title;
    [self addChildViewController:vc];
}


@end
